package com.example.recyclerviewcheckitemdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    protected CheckItemAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        adapter = new CheckItemAdapter(this, new CheckItemAdapter.CheckItemListener() {
            @Override
            public void onCheckItem(int position) {
                Toast.makeText(MainActivity.this,"点击了:"+position,Toast.LENGTH_LONG).show();
            }
        });
        RecyclerView recyclerView = findViewById(R.id.recycler);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        adapter.addItem(new CheckItemAdapter.Item(true));
        adapter.addItem(new CheckItemAdapter.Item(false));
        adapter.addItem(new CheckItemAdapter.Item(false));
        adapter.addItem(new CheckItemAdapter.Item(false));
        adapter.addItem(new CheckItemAdapter.Item(false));
    }
}